import Vue from 'vue'
import App from './App.vue'

import ElementUI from 'element-ui';
import router from '@/router/index'
import 'element-ui/lib/theme-chalk/index.css';


// import './assets/icons'
import axios from 'axios'
import store from './store'
import * as echarts from 'echarts';


import less from 'less'




Vue.use(less)

Vue.prototype.$echarts = echarts
Vue.prototype.$http = axios

// Vue.prototype.$websocket = "ws://127.0.0.1/websocket/"
axios.defaults.baseURL = 'http://127.0.0.1'
Vue.prototype.$websocket = "ws://127.0.0.1/teamWebsocket/"

// Vue.prototype.$websocket = "ws://124.223.12.164/websocket/"
// axios.defaults.baseURL = 'http://124.223.12.164'

// 添加请求拦截器
axios.interceptors.request.use((config) => {
  // 在发送请求之前做些什么
  if (!store.state.myToken) {
    return config
  }
  config.headers.Authorization = 'Bearer ' + store.state.myToken
  return config
})

function routerToIndex() {
  window.localStorage.removeItem("myToken")
  router.push("/")
}

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
  if (response.data.code == 401) {
    routerToIndex()
  }
  // 对响应数据做点什么
  const {data: res} = response
  if (res.code === 500) {
    return -1
  }
  return res
})

Vue.use(ElementUI);


Vue.config.productionTip = false

new Vue({
  store,
  router,
  render: h => h(App),
}).$mount('#app')